package com.example.controller;

import com.example.config.MqttSendClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author LiangJingSong
 * @version 1.0
 * @date 2024/8/3 16:18
 * @description
 */
@RestController
@RequestMapping("/mqtt")
public class MqttController {

    @Autowired
    private MqttSendClient mqttSendClient;

    @PostMapping(value = "/publishTopic")
    public String publishTopic(String topic, String sendMessage) {
        System.out.println("topic:" + topic);
        System.out.println("message:" + sendMessage);
//        this.mqttSendClient.publish(false, topic, sendMessage);
        this.mqttSendClient.publish(false, "server", new byte[]{0x01, 0x10, 0x00, 0x19, 0x00,
                0x01, 0x02, 0x00, 0x01, 0x65, (byte) 0x99});
        return "topic:" + topic + "\nmessage:" + sendMessage;
    }

}

